#ifndef FILEDISPATCHER_H
#define FILEDISPATCHER_H

#include <QObject>
#include <QList>
#include <QDir>
#include <QUrl>
#include <QFile>
#include <QFtp>
#include <QTimer>
#include "ftpfile.h"

class FileDispatcher : public QObject
{
Q_OBJECT
private slots:
	void ftpDone(bool error);
	void ftpCommandFinished(int id, bool error);
	void ftpDataTransferProgress(qint64 done, qint64 total);
	void ftpStateChanged(int state);
	void connectionTimeout();

signals:
	void allJobsDone();
	void abnormalExit();
	void fileLoadingStart(const QString &message);
	void fileLoadingDone(const QString &message);
	void fileSizeInit(int min, int max);
	void fileLoadingProgress(int v);
	void unhandledError(const QString &message);

public:
	FileDispatcher();
	void loadingProcess();

protected:
	FTPFile *getFileByName(const QString &nme);
	QList<FTPFile *> files;
	int current_file;

	void setURL(const QString &u);
	void setLogin(const QString &usr, const QString &psw);
	void setConfigFile(const QString &f);
	void setTemporaryFolder(const QString &f);
	void setConectionTimeout(int v);
	const QUrl &getURL();
	const QString &getUser();
	const QString &getPassword();
	const QString &getConfigFile();
	const QString &getTemporaryFolder();
	int getConectionTimeout();
	void runExecutableFiles();
        void saveConfigFile();
        bool mkdir(FTPFile *file);

private:
	QString user_name;
	QString password;
	QString config_file;
	QString temporary_folder;
	QString str_url;
	QUrl url;
	QString ftp_folder;
	int loading_stage;
	QFtp ftp;
	QFile ftp_file;
	QDir *tmp_dir;
	QTimer timer;
	int timeout;
	bool new_file;

	friend class LocalXMLConfig;
	friend class RemoteXMLConfig;
};

#endif // FILEDISPATCHER_H
